FROM golang:1.23-alpine AS builder
WORKDIR /export/alertmanagerWebhook
ENV GO111MODULE=on \
    GOPROXY=https://goproxy.cn,direct
# 复制源代码
COPY . .
# 构建应用
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o alertmanager-webhook ./cmd/main.go
# 第二阶段：运行环境
FROM alpine:latest
# 安装 tzdata 包，设置时区
RUN apk update && apk add --no-cache tzdata
# # 设置容器的时区为宿主机的时区（例如，Asia/Shanghai）
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/Shanghai" > /etc/timezone
# 设置工作目录
WORKDIR /export/alertmanagerWebhook
# 从构建阶段复制二进制文件和配置文件
COPY --from=builder /export/alertmanagerWebhook/alertmanager-webhook .
COPY --from=builder /export/alertmanagerWebhook/settings.yaml .
# 创建日志目录
RUN mkdir -p /export/alertmanagerWebhook/logs
EXPOSE 19093
# 启动应用
ENTRYPOINT ["sh", "-c", "./alertmanager-webhook && tail -f /export/alertmanagerWebhook/logs/alertmanagerWebhook.log"]